package com.fr.report.io;

import com.fr.base.FRContext;
import com.fr.base.core.list.IntList;
import com.fr.report.PageInfo;
import com.fr.report.PageSet;
import com.fr.report.PaperSetting;
import com.fr.report.Report;
import com.fr.report.ReportPage;
import com.fr.report.ResultWorkBook;
import com.fr.report.core.cal.LayerPageReport;
import com.fr.report.core.cal.LayerReport;
import com.fr.report.io.core.PageToSheetExcelExporterReport;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PageToSheetExcelExporter extends ExcelExporter
{
  public PageToSheetExcelExporter(List paramList)
  {
    super(paramList);
  }

  public void export(OutputStream paramOutputStream, ResultWorkBook paramResultWorkBook)
    throws Exception
  {
    export(paramOutputStream, paramResultWorkBook, false);
  }

  protected void exportBook(ResultWorkBook paramResultWorkBook, HSSFWorkbook paramHSSFWorkbook, List paramList1, List paramList2, List paramList3, boolean paramBoolean)
    throws Exception
  {
    for (int i = 0; i < paramResultWorkBook.getReportCount(); ++i)
    {
      localObject = paramResultWorkBook.getReport(i);
      paramList3.add(localObject);
    }
    ArrayList localArrayList = new ArrayList(paramResultWorkBook.getReportCount());
    Object localObject = new IntList(paramResultWorkBook.getReportCount());
    int j = 0;
    for (int k = 0; k < paramResultWorkBook.getReportCount(); ++k)
      if ((paramResultWorkBook.getReport(k) instanceof LayerPageReport) || (paramResultWorkBook.getReport(k) instanceof LayerReport))
      {
        FRContext.getLogger().log(Level.WARNING, "Report index :" + (k + 1) + ", Layer Report can not export by this way");
      }
      else if (paramResultWorkBook.getReport(k) != null)
      {
        localArrayList.add(((Report)paramList3.get(k)).generateReportPageSet((this.paperSettingList == null) ? null : (PaperSetting)this.paperSettingList.get(k)).getTraversingCase());
        ((IntList)localObject).add(j);
        j += ((PageSet)localArrayList.get(localArrayList.size() - 1)).size();
      }
    for (k = 0; k < localArrayList.size(); ++k)
    {
      PageSet localPageSet = (PageSet)localArrayList.get(k);
      for (int l = 0; l < localPageSet.size(); ++l)
      {
        ReportPage localReportPage = localPageSet.getPage(l);
        localReportPage.getPageInfo().setTotalPages(j);
        localReportPage.setCurrentPageNumber(localReportPage.getCurrentPageNumber() + ((IntList)localObject).get(k));
        innerExportReport(new PageToSheetExcelExporterReport(localReportPage), paramResultWorkBook.getReportExportAttr(), "Page" + localReportPage.getCurrentPageNumber(), paramHSSFWorkbook, paramList1, paramList2, k);
      }
      if (!(paramBoolean))
        localPageSet.release();
    }
  }
}